----------------------------
-- Simplistic Street
-- by Arran
--
-- Project Started - October 20, 2009
-- Completion -None
----------------------------

surface.CreateFont("MenuItem", 14, 0, true, false, "ScoreboardText3")
surface.CreateFont("MenuItem", 30, 600, true, false, "ScoreboardText4")

--[[local scoreboard = nil

function GM:HUDDrawScoreboard()
	return false
end

function GM:ScoreboardShow()
	if (!scoreboard or !scoreboard:IsValid()) then
		scoreboard = vgui.Create("simplisticstreet_scoreboard")
	end
	
	scoreboard:SetVisible(true)
	scoreboard:Update()
	gui.EnableScreenClicker(true)
end

function GM:ScoreboardHide()
	scoreboard:SetVisible(false)
	gui.EnableScreenClicker(false)
end

local PANEL = {}

function PANEL:Init()
	self.count = 0
	
	self:SetSize(514, 300)
	self:Center()
	self:SetTitle("[Simplistic Street] | Www.Opacityservers.co.uk | Created by Arran and Jammie Dodger")
	self:SetDraggable(false)
	self:ShowCloseButton(false)
	
	self.list = vgui.Create("DPanelList", self)
	self.list:SetPos(10, 32)
	self.list:SetSize(self:GetWide() -20, self:GetTall() -40)
	self.list:SetSpacing(1)
	self.list:EnableVerticalScrollbar(true)
end

function PANEL:Think()
	if (self.count != #player.GetAll()) then
		self:Update()
		
		self.count = #player.GetAll()
	end
end

function PANEL:Update()
	self.list:Clear()

	for k, v in pairs(player.GetAll()) do
		local panel = vgui.Create("DPanel")
		panel:SetTall(40)
		
		panel.Paint = function(self)
			local w, h = self:GetSize()
		
			--surface.SetDrawColor(color_white)
			--surface.DrawOutlinedRect(2, 2, w-4, h -4)
			
			draw.SimpleText(v:Nick(), "ScoreboardText3", 60, 21, color_black, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
			draw.SimpleText(v:Nick(), "ScoreboardText3", 59, 20, color_white, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
			
			draw.SimpleText(team.GetName(v:Team()), "ScoreboardText3", 251, 21, color_black, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
			draw.SimpleText(team.GetName(v:Team()), "ScoreboardText3", 250, 20, color_white, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
			
			draw.SimpleText(v:Ping(), "ScoreboardText3", 446, 21, color_black, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
			draw.SimpleText(v:Ping(), "ScoreboardText3", 445, 20, color_white, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
		end
		
		local avatar = vgui.Create("AvatarImage", panel)
		avatar:SetPos(4, 4)
		avatar:SetSize(32, 32)
		avatar:SetPlayer(v)
		
		self.list:AddItem(panel)
	end
end

vgui.Register("simplisticstreet_scoreboard", PANEL, "DFrame")--]]

local scoreboard = nil

function GM:HUDDrawScoreboard()
	return false
end

function GM:ScoreboardShow()
	if (!scoreboard or !scoreboard:IsValid()) then
		scoreboard = vgui.Create("simplisticstreet_scoreboard")
	end
	
	scoreboard:SetVisible(true)
	scoreboard:Update()
	gui.EnableScreenClicker(true)
end

function GM:ScoreboardHide()
	scoreboard:SetVisible(false)
	gui.EnableScreenClicker(false)
end

local PANEL = {}

function PANEL:Init()
	self.count = 0
	
	self:SetSize(514, 380)
	self:Center()
	--self:SetTitle("[Simplistic Street] | Www.Opacityservers.co.uk | Created by Arran and Jammie Dodger")
	self:SetTitle("", true)
	self:SetDraggable(false)
	self:ShowCloseButton(false)

	self.label = vgui.Create("DPanel", self)
	self.label:SetPos(0,0)
	self.label:SetSize(self:GetTall(), self:GetWide())
	self.label.Paint = function()
		draw.SimpleText("Simplistic Street", "ScoreboardText4", self:GetWide()/2, 25, Color(255,255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
		draw.SimpleText("Created by Jammie Dodger and Arran", "ScoreboardText3", self:GetWide()/2, 50, Color(255,255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
		--draw.SimpleText("OpacityServers.co.uk", "ScoreboardText3", ScrW()/2 - self:GetWide()/2, 70, Color(255,255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
	end
	
	self.list = vgui.Create("DPanelList", self)
	self.list:SetPos(10, 100)
	self.list:SetSize(self:GetWide() -20, self:GetTall() -120)
	self.list:SetSpacing(1)
	self.list:EnableVerticalScrollbar(true)
end

function PANEL:Think()
	if (self.count != #player.GetAll()) then
		self:Update()
		
		self.count = #player.GetAll()
	end
end

function PANEL:Update()
	self.list:Clear()

	for k, v in pairs(player.GetAll()) do
		local panel = vgui.Create("DPanel")
		panel:SetTall(40)
		
		panel.Paint = function(self)
			local w, h = self:GetSize()
		
			--surface.SetDrawColor(color_white)
			--surface.DrawOutlinedRect(2, 2, w-4, h -4)
			
			draw.SimpleText(v:Nick(), "ScoreboardText3", 60, 21, color_black, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
			draw.SimpleText(v:Nick(), "ScoreboardText3", 59, 20, color_white, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
			
			draw.SimpleText(team.GetName(v:Team()), "ScoreboardText3", 251, 21, color_black, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
			draw.SimpleText(team.GetName(v:Team()), "ScoreboardText3", 250, 20, color_white, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
			
			draw.SimpleText(v:Ping(), "ScoreboardText3", 446, 21, color_black, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
			draw.SimpleText(v:Ping(), "ScoreboardText3", 445, 20, color_white, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
		end
		
		local avatar = vgui.Create("AvatarImage", panel)
		avatar:SetPos(4, 4)
		avatar:SetSize(32, 32)
		avatar:SetPlayer(v)
		
		self.list:AddItem(panel)
	end
end

vgui.Register("simplisticstreet_scoreboard", PANEL, "SSFrame")


function GM:HUDDrawTargetID()

    local tr = utilx.GetPlayerTrace( LocalPlayer(), LocalPlayer():GetCursorAimVector() )
    local trace = util.TraceLine( tr )
    if (!trace.Hit) then return end
    if (!trace.HitNonWorld) then return end
    
    local text = "Error"
    local font = "TargetID"
    
    if (trace.Entity:IsPlayer()) then
        text = trace.Entity:Nick()
    else
        return
    end
    
    surface.SetFont( font )
    local w, h = surface.GetTextSize( text )
    
    local MouseX, MouseY = gui.MousePos()
    
    if ( MouseX == 0 && MouseY == 0 ) then
    
        MouseX = ScrW() / 2
        MouseY = ScrH() / 2
    
    end
    
    local x = MouseX
    local y = MouseY
    
    x = x - w / 2
    y = y + 30
    
    draw.SimpleText( text, font, x+1, y+1, Color(0,0,0,120) )
    draw.SimpleText( text, font, x+2, y+2, Color(0,0,0,50) )
    draw.SimpleText( text, font, x, y, self:GetTeamColor( trace.Entity ) )
    
    y = y + h + 5
    
    local text = trace.Entity:Health() .. "/100 HP"
	local font = "TargetIDSmall"
    
    surface.SetFont( font )
    local w, h = surface.GetTextSize( text )
    local x =  MouseX  - w / 2
    
    draw.SimpleText( text, font, x+1, y+1, Color(0,0,0,120) )
    draw.SimpleText( text, font, x+2, y+2, Color(0,0,0,50) )
    draw.SimpleText( text, font, x, y, self:GetTeamColor( trace.Entity ) )
	
	y = y + h + 5
	
	if LocalPlayer():Armor() > 0 then
		local text = trace.Entity:Armor() .. "/100 Armor"
		
		surface.SetFont( font )
		local w, h = surface.GetTextSize( text )
		local x =  MouseX  - w / 2
		
		draw.SimpleText( text, font, x+1, y+1, Color(0,0,0,120) )
		draw.SimpleText( text, font, x+2, y+2, Color(0,0,0,50) )
		draw.SimpleText( text, font, x, y, self:GetTeamColor( trace.Entity ) )	
	end
end
